package com.zx.wangyixinwen.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.android.volley.toolbox.NetworkImageView;
import com.zx.wangyixinwen.MyRequestQueue;
import com.zx.wangyixinwen.R;
import com.zx.wangyixinwen.bean.Vodio;

import java.net.URI;
import java.util.List;

/**
 * Created by dllo on 16/1/20.
 */
public class SeeAdatper extends BaseAdapter {
    private List<Vodio> datas;
    private Context context;

    public SeeAdatper(List<Vodio> datas, Context context) {
        this.datas = datas;
        this.context = context;
    }

    @Override
    public int getCount() {
        return null == datas ? 0 : datas.get(0).getVideoList().size();
    }

    @Override
    public Object getItem(int position) {
        return datas.size() > 0 && datas != null ? datas.size() : 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_see_vodio, null);
            holder = new ViewHolder();
            holder.tv_description = (TextView) convertView.findViewById(R.id.tv_item_see_description);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_item_see_title);
            holder.vv = (VideoView) convertView.findViewById(R.id.vv_item_see);
            holder.tv_description.setText(datas.get(0).getVideoList().get(position).getDescription());
            holder.tv_title.setText(datas.get(0).getVideoList().get(position).getTitle());
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Uri uri = Uri.parse(datas.get(0).getVideoList().get(position).getMp4_url());
        holder.vv.setMediaController(new MediaController(context));
        holder.vv.setVideoURI(uri);
        holder.vv.requestFocus();
        holder.tv_description.setText(datas.get(0).getVideoList().get(position).getDescription());
        holder.tv_title.setText(datas.get(0).getVideoList().get(position).getTitle());
        return convertView;
    }

    class ViewHolder {
        private VideoView vv;
        private TextView tv_title, tv_description;
    }
}
